/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ModelLayer;

import java.util.ArrayList;


/**
 *
 * @author Claus
 */
public class SalesOrder
{
	public static final int DELIVERYCHARGE = 45;
	public static final int CASHONDELIVERYCHARGE = 25;
	public static final float BUSINESSDISCOUNT = 0.1f;

	public static final int NOTDELIVERED = 0;
	public static final int DELIVERED = 1;


	int salesID;
	String date;
	int deliveryStatus;
	String deliveryDate;
	ArrayList<SalesLineItem> salesItems;
	Invoice orderInvoice;
	Customer customer;

	public SalesOrder()
	{
		this.salesID = 0;
		this.date = "";
		this.deliveryStatus = NOTDELIVERED;
		this.deliveryDate = "";
		this.salesItems = new ArrayList<SalesLineItem>();
		this.orderInvoice = null;
		this.customer = null;
	}

	public SalesOrder(int salesID, String date, int deliveryStatus, String deliveryDate, Invoice orderInvoice, Customer customer)
	{
		this.salesID = salesID;
		this.date = date;
		this.deliveryStatus = deliveryStatus;
		this.deliveryDate = deliveryDate;
		this.salesItems = new ArrayList<SalesLineItem>();
		this.orderInvoice = orderInvoice;
		this.customer = customer;

	}

	public int getSalesID()
	{
		return salesID;
	}

	public void setSalesID(int salesID)
	{
		this.salesID = salesID;
	}
	
	public int getDeliveryStatus()
	{
		return deliveryStatus;
	}

	public void setDeliveryStatus(int deliveryStatus)
	{
		this.deliveryStatus = deliveryStatus;
	}

	public String getDeliveryDate()
	{
		return deliveryDate;
	}

	public void setDeliveryDate(String deliveryDate)
	{
		this.deliveryDate = deliveryDate;
	}

	public String getDate()
	{
		return date;
	}

	public void setDate(String date)
	{
		this.date = date;
	}

	public ArrayList<SalesLineItem> getSalesItems()
	{
		return salesItems;
	}

	public void setSalesItems(ArrayList<SalesLineItem> salesItems)
	{
		this.salesItems = salesItems;
	}

	public void addSalesItem(SalesLineItem item)
	{
		salesItems.add(item);
	}

	public void removeSalesItem(SalesLineItem item)
	{
		salesItems.remove(item);
	}

	public Customer getCustomer()
	{
		return customer;
	}

	public void setCustomer(Customer customer)
	{
		this.customer = customer;
	}

	public Invoice getOrderInvoice()
	{
		return orderInvoice;
	}

	public void setOrderInvoice(Invoice orderInvoice)
	{
		this.orderInvoice = orderInvoice;
	}

	public float getPrice()
	{
		float price = 0.0f;

		for(SalesLineItem item : salesItems)
		{
			price += item.getPrice();
		}

		if(customer.getType() == Customer.PRIVATE && price < 2500 && orderInvoice.getPaymentMethod() == Invoice.CASHONDELIVERY)
		{
			price += DELIVERYCHARGE + CASHONDELIVERYCHARGE;
		}
		else if(customer.getType() == Customer.PRIVATE && price < 2500 && orderInvoice.getPaymentMethod() != Invoice.CASHONDELIVERY)
		{
			price += DELIVERYCHARGE;
		}
		else if(customer.getType() == Customer.PRIVATE && price > 2500 && orderInvoice.getPaymentMethod() == Invoice.CASHONDELIVERY)


		{
			price += CASHONDELIVERYCHARGE;
		}
		else if(customer.getType() == Customer.BUSINESS && price > 1500)
		{
			price = price * (1.0f-BUSINESSDISCOUNT);
		}
		else 
		{
			// do nothing
		}

		return price;
	}

	public void delete()
	{
		for(SalesLineItem item : salesItems)
		{
			item.removeAllItems();
		}
	}

}
